/*
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 */

package com.ecarx.systemui.plugin.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.PagerAdapter;

import com.ecarx.systemui.plugin.R;
import com.ecarx.systemui.plugin.ui.custom.BluetoothListView;
import com.ecarx.systemui.plugin.ui.custom.HotspotOptView;
import com.ecarx.systemui.plugin.ui.custom.WifiListView;

import java.util.ArrayList;
import java.util.List;

public class BtWifiAdapter extends PagerAdapter {

    private final List<String> titles = new ArrayList<>();

    private final List<View> views = new ArrayList<>();


    @SuppressLint("InflateParams")
    public BtWifiAdapter(Context context) {

        titles.clear();
        titles.add(context.getString(R.string.dialog_bt));
        titles.add(context.getString(R.string.dialog_wifi));
        titles.add(context.getString(R.string.hotspot_name));

        views.clear();
        views.add(new BluetoothListView(context));
        views.add(new WifiListView(context));
        views.add(new HotspotOptView(context));

    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = views.get(position);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        View convertView = (View) object;
        container.removeView(convertView);
    }

    @Override
    public int getCount() {
        return views.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }
}
